package com.changan.controller;

import com.changan.entity.Department;
import com.changan.response.Result;
import com.changan.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author NieChangan
 * @since 2022-12-13
 */
@Api(tags = "部门管理")
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Resource
    private DepartmentService departmentService;

    @GetMapping("/selectDepartNameAndCount")
    @ApiOperation(value = "获取部门名称及人数",notes = "......")
    public Result selectDepartNameAndCount(){
        List<Department> departments = departmentService.selectDepartNameAndCount();
        //List<Department> collect = departments.stream().filter(Objects::nonNull).collect(Collectors.toList());
        //在前端搞定
        return Result.ok().data("departments",departments);
    }
}
